<?php

namespace App\Utils\Sms;

use Flc\Dysms\Client;
use Flc\Dysms\Request\SendSms;

## 阿里大鱼短信
class AliSms implements SmsInterface
{
    public string $signName = '';

    /**
     * 构造函数
     * @param string $signName
     */
    public function __construct(string $signName)
    {
        $this->signName = $signName;
    }

    /**
     * 设置短信签名
     * @param bool $includeBracket
     * @return string
     */
    public function setSignName(bool $includeBracket): string
    {
        return $includeBracket ? '【'. $this->signName . '】' : $this->signName;
    }

    /**
     * 发送验证码
     * @param string $mobile
     * @param int $verifyCode
     * @return true
     */
    public function send(string $mobile, int $verifyCode): bool
    {
        $client  = new Client([
            'accessKeyId'       => 'LTAIOyGnwFsdHLuF',
            'accessKeySecret'   => '0F7vqdHLkneUJI6wWeSRmCwttPaJ5u',
        ]);
        $sendSms = new SendSms;
        $sendSms->setPhoneNumbers($mobile);
        $sendSms->setSignName($this->setSignName(false));
        $sendSms->setTemplateCode('SMS_193512471');
        $sendSms->setTemplateParam(['code' => $verifyCode]);
        $sendSms->setOutId(time() . rand(10, 99));
        $client->execute($sendSms);
        return true;
    }
}
